package com.yisoo.ubag.iot.entity;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;
import java.util.Date;

import com.yisoo.ubag.iot.vo.HeartStatusMqttContentVo;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

/**
 * 
 * 
 * @author mmciel
 * @email 761998179@qq.com
 * @date 2021-03-07 13:09:16
 */
@Data
@TableName("iot_status")
@NoArgsConstructor
public class StatusEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 
	 */
	@TableId
	private Integer statusId;
	/**
	 * 
	 */
	private String deviceName;
	/**
	 * 
	 */
	private String productKey;
	/**
	 * 
	 */
	private String msg;
	/**
	 * 
	 */
	private Integer msgCode;
	/**
	 * 
	 */
	private String gps;
	/**
	 * 
	 */
	private Double disXData;
	/**
	 * 
	 */
	private String disXType;
	/**
	 * 
	 */
	private Double disYData;
	/**
	 * 
	 */
	private String disYType;
	/**
	 * 
	 */
	private Double battery;
	/**
	 * 
	 */
	private Double hum;
	/**
	 * 
	 */
	private Double tem;
	/**
	 * 
	 */
	private Integer status;
	/**
	 * 
	 */
	private Integer wbao;
	/**
	 * 
	 */
	private Integer nbao;


	public StatusEntity(MsgBackEntity msgBackEntity){
		//在状态改变消息中的content数据抽象到VO
		HeartStatusMqttContentVo heartStatusMqttContentVo = JSONObject.parseObject(msgBackEntity.getMContent(), HeartStatusMqttContentVo.class);

		BeanUtils.copyProperties(heartStatusMqttContentVo,this);
		this.deviceName = msgBackEntity.getDeviceName();
		this.productKey = msgBackEntity.getProductKey();
		//gps解析
		String gps = heartStatusMqttContentVo.getGps();
		String[] strs = gps.split(",");
//		for (String s:strs){
//			System.out.println(">>>["+s+"]");
//		}
		try{
			this.disXData = Double.parseDouble(strs[0]);
			this.disXType = strs[1];
			this.disYData = Double.parseDouble(strs[2]);
			this.disYType = strs[3];
		}catch (Exception e){
			for (String s:strs){
				System.out.println(">>>["+s+"]");
			}
		}

	}
}
